<?php
namespace Tbf\Bundle\PackageBundle\RelationPackage;
use Tbf\Bundle\PackageBundle\AbstractController;
use Tbf\Bundle\PackageBundle\RelationPackage\CreateAction;
use Tbf\Bundle\PackageBundle\RelationPackage\DeleteAction;
use Tbf\Bundle\PackageBundle\RelationPackage\ListAction;
use Tbf\Bundle\PackageBundle\RelationPackage\SetAction;
use Tbf\Bundle\AjkApiBundle\Annotation\Api;

abstract class RelationController extends AbstractController
{
    protected function getRouteConfig()
    {
        return array(
            'list'=>'@listAction',
            'set'=>'@setAction',
            'create'=>'@createAction',
            'delete'=>'@deleteAction',
            'total'=>'@totalAction',
            'bulk_create_many_many'=>'@bulkCreateManyManyAction',
            'bulk_delete_many_many'=>'@bulkDeleteManyManyAction',
        );
    }

    /**
     * @Api
     */
    public function listAction($input)
    {
        return $this->executeAction($input,new ListAction());
    }
    /**
     * @Api
     */
    public function setAction($input)
    {
        return $this->executeAction($input,new SetAction());
    }
    /**
     * @Api
     */
    public function createAction($input)
    {
        return $this->executeAction($input,new CreateAction());
    }

    /**
     * @Api
     */
    public function deleteAction($input)
    {
        return $this->executeAction($input,new DeleteAction());
    }
    /**
     * @Api
     */
    public function totalAction($input)
    {
        return $this->executeAction($input,new TotalAction());
    }

    /**
     * @Api
     */
    public function bulkCreateManyManyAction($input)
    {
        return $this->executeAction($input,new BulkCreateManyManyAction());
    }

    /**
     * @Api
     */
    public function bulkDeleteManyManyAction($input)
    {
        return $this->executeAction($input,new BulkDeleteManyManyAction());
    }
    public function executeAction($input,$action)
    {
        $action->setContainer($this->getContainer());
        $action->setConfig($this->getRelationPackageConfig());

        return $action->execute($input);
    }
    /**
     * @return RelationControllerConfig
     */
    abstract protected function getRelationPackageConfig();
}
